package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.common.Common;
import com.example.demo.common.SexEnum;
import com.example.demo.entity.User;
import org.springframework.http.ResponseEntity;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import top.starp.util.R;

import javax.annotation.Resource;

@RestController
public class KafkaController {
    @Resource
    KafkaTemplate<String,Object> kafkaTemplate;

    @PostMapping("/postMessage")
    public ResponseEntity sendMessage(){
        User user = new User();
        user.setId(1);
        user.setNickName("深蓝梦境");
        user.setTelNumber("13811999999");
        user.setPassword("admin");
        user.setSex(Common.Sex.MALE);
//        user.setId(1).setNickName("深蓝梦境").setTelNumber("13811999999").setPassword("admin").setSex(SexEnum.MALE.value);
//        user.setId(1).setNickName("深蓝梦境").setTelNumber("13811999999").setPassword("admin").setSex(Common.Sex.MALE);
        kafkaTemplate.send("demo", JSONObject.toJSONString(user));
        return R.ok("发送成功");
    }
}
